﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ChatApplication_Wpf
{
    /// <summary>
    /// Interaction logic for LoginPage.xaml
    /// </summary>
    public partial class LoginPage : UserControl
    {
        App app = Application.Current as App;        
        public LoginPage()
        {
            InitializeComponent();     
        }      

        public void ClearText()
        {
            textBox1.Text = "";
            textBox2.Password = "";
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Password != "")
            {
                ChatServerEntities1 entities = new ChatServerEntities1();
                var result = (from d in entities.User_Details
                              where d.User_Id == textBox1.Text && d.Password == textBox2.Password
                              select d).SingleOrDefault();
                if (result != null)
                {
                    app.Username = textBox1.Text;
                    app.Header.Content = new HeaderPage();
                    app.Control.Content = new HomePage();
                }
                else
                {
                    label1.Content = "Username or Password may be Incorrect";                    
                }
                ClearText();
            }
            else
            {
                label1.Content = "Please enter Username and Password";
            }
        }

       

        private void textBox1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            label1.Content = "";
        }

        private void textBox2_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            label1.Content = "";
        }
    }
}
